/**
 * @author KujoMiva
 * @name HomeScreen.ts
 * @desc 开始界面
 * @time 2020年03月01日 19:41:52 星期天
 */
class HomeScreen extends egret.DisplayObjectContainer {
  private animationSpeed: number = 800

  public constructor() {
    super()
    this.once(egret.Event.ADDED_TO_STAGE, this.init, this)
  }

  private init() {
    this.createBook()
    this.createBtnStart()
  }

  private createBook() {
    const book = Utils.createBitmapByName('book_home_png')
    this.addChild(book)
    book.anchorOffsetY = book.height / 2
    book.anchorOffsetX = book.width
    book.x = (this.stage.stageWidth / 2) + (book.width / 2)
    book.y = this.stage.stageHeight / 2 + 50
  }

  private createBtnStart() {
    const btn = Utils.createBitmapByName('enter_png')
    this.addChild(btn)
    btn.x = 170
    btn.y = 550
    btn.touchEnabled = true
    btn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
      egret.Tween.get(this)
        .to({ x: -this.width }, this.animationSpeed)
        .call(() => {
          this.stage.dispatchEvent(new egret.Event('gotoPageFirst'))
          this.parent.removeChild(this)
        })
    }, this)
  }
}